Building on my answer to a related previous question, I'm putting an answer I sketched in chat into a proper form.
The key idea behind this whole solution is the fact that you can use the dot product between a vector of length $1$ and another vector to compute the length of the projection of the second vector onto the first. I imagine this as computing the component of a given vector into a given direction.
Computing the distances
The first thing you need is a vector which has length 1 and lies in your horizontal plane and is orthogonal to the direction of your three lines. I'll call this vector $u$. In general, you can compute such a vector using the cross product:
\begin{align*} u' &= h\times (C-D) \\ u &= \frac{u'}{\lVert u'\rVert} = \frac{1}{\sqrt{u'\cdot u'}}u' \end{align*}
Here $h$ is the normal of your horizontal plane, and $C-D$ is the direction vector of your line $CD$.
If $h$ has simple coordinates like $(0,0,1)$, then you'd have $C-D=(x,y,z)$ for some numbers $x,y,z\in\mathbb R$. In that case you could avoid actually computing the cross product, and simply write $u'=(y,-x,0)$. You'd still have to normalize as above, though.
So now you have this vector $u$, you can use it to measure distances between projected lines:
\begin{align*} d_1 &= \left\lvert u\cdot (A - C)\right\rvert \\ d_2 &= \left\lvert u\cdot (E - C)\right\rvert \end{align*}
Moving the line
Now you have to see which of these numbers is the smaller one, as that indicates which line you want to change. For now I'll assume that $d_1; the other case works in the same way by simply exchanging corresponding variables.
Now you know that you want to move $AB$ in such a way that its distance scales by a factor of $\frac{d_2}{d_1}$. As you require the movement to go in the direction of “steepest incline”, you probably want the displacement vector to be orthogonal to the direction of the three original lines. (In the case of not really horizontal lines, there would be a difference, but I take it that you still want to move “directly” away from $CD$.) So what we do is we take the vector pointing from $C$ to $A$, and remove from that vector the component in direction $D-C$.
\begin{align*} v = (A-C) - \frac{(A-C)\cdot(D-C)}{(D-C)\cdot(D-C)}(D-C) = (A-C) - \left((A-C)\cdot\frac{D-C}{\lVert D-C\rVert}\right)\frac{D-C}{\lVert D-C\rVert} \end{align*}
The rightmost version in the above formulation shows that I'm thinking about a Version of the vector $D-C$ which has been normalized, i.e. scaled to unit length. The version to the left demonstrates how you can obtain the same result without actually computing the square root. So the left version is the one I'd implement, but the right version might be easier to comprehend.
The vector $v$ as computed above will point from any point on the infinite line $CD$ to the point on the infinite line $AB$ along a path of steepest incline.
So now you can take this vector $v$ and use it to compute the displacement you need.
\begin{align*} v' &= \frac{d_2}{d_1} v - v = \left(\frac{d_2}{d_1} - 1\right)v \\ A' &= A + v' \\ B' &= B + v' = A' + (B - A) \end{align*}
Now you have the points of the new line $A'B'$ which lies in the plane $ABCD$, and which will have the desired distance in the projection onto the horizontal plane.