This is false ; another friend has found a nice counter-example. The idea is the following: consider the two following curves, $C_1$ the vertical axis and $C_2$ your favourite curve that coincides with $C_1$ for negative $y$ but then escapes the vertical axis, for instance, take for $C_2$ the set of $(0,y)$ for $y \leq 0$ union the set of $(e^{-1/y^2},y)$ for positive $y$.
We will construct a function $f$ that satisfies the assumptions of the exercise but whose image is the union of $C_1$ and $C_2$. In order to understand how this is possible, I consider the sets $\Gamma_x = f(\{x\} \times \mathbb{R})$. Then $\Gamma_x$ will be $C_1$ for $x < 2$, $C_2$ for $x > 3$ and the demi-axis $\{(0,y), y < 0\}$ for $x$ between $2$ and $3$.
The way of "interpolating" these curves is very nice. Let $g_1$ and $g_2$ be standard paramatrizations of $C_1$ and $C_2$: $g_1(y) = (0,y)$ and $g_2(y) = (0,y)$ for negative $y$ and $(e^{-1/y^2},y)$ for positive $y$. Consider $\lambda(x)$ a strictly increasing smooth function from $\mathbb{R}$ to itself, which tends to $0$ at $+\infty$ and to $-\infty$ at $-\infty$. Finally consider $\mu(z)$ a smooth function from $\mathbb{R}$ to itself which is equal to $1$ for $z \leq 1$ or $z \geq 4$, to $0$ for $z$ between $2$ and $3$ and which is always between $0$ and $1$.
Define $w(x,y)$ as the barycenter in $\mathbb{R}$ of $y$ and $\lambda(y)$ for the coefficient $\mu(x)$, that is $w(x,y) = \mu(x)y + (1-\mu(x))\lambda(y)$. By construction, at $y$ fixed, $w(x,y)$ is $y$ for $x\leq 1$, $\lambda(y)$ for $x$ between $2$ and $3$ and is sent again to $y$ for $x \geq 4$. In particular, for any $y$, $w(x,y)$ is negative for $x$ between $2$ and $3$.
Now consider the function $f(x,y) = g_1(w(x,y))$ for $x \leq 3$ and $f(x,y) = g_2(w(x,y))$ for $x \geq 2$. This is well-defined since $g_1$ and $g_2$ coincide for a negative argument. By construction, $f$ is smooth, and has the properties stated in the second paragraph. We just have to show that $f$ is of constant rank $1$. Clearly, it cannot be of rank $2$ since it factorizes thru the map $w$ with $1$-dimensional image. Moreover, $g_1$ and $g_2$ are immersions and $w$ is a submersion (here we use that $\lambda$ is strictly increasing), so that by composition, the differential of $f$ cannot vanish.
This concludes the proof. I encourage you to make a picture; this is very nice.