The geodesic equation in polar coordinates reduces to the coupled differential equations \begin{align} \dot\phi &= \frac{\ell}{r^2} \\ \dot{r}^2 &= 1 - \frac{\ell^2}{r^2} \end{align} where the constant $\ell$ is the angular momentum about the origin (per unit mass), and where we have used arclength (here labeled $\lambda$) as the parameter (so that the curve is traversed at unit speed). We now proceed to solve these equations.
Separating variables, we have \begin{equation} \frac{dr}{\sqrt{1-\frac{\ell^2}{r^2}}} = \pm d\lambda \end{equation} so that \begin{equation} \pm\lambda = \int \frac{r\,dr}{\sqrt{r^2-\ell^2}} = \sqrt{r^2-\ell^2} + \hbox{constant} \end{equation} and we can ignore the integration constant, as it merely shifts the origin of $\lambda$. Thus, \begin{equation} r^2 = \lambda^2 + \ell^2 \label{rpolar} \end{equation} and we have \begin{equation} \dot\phi = \frac{\ell}{r^2} = \frac{\ell}{\lambda^2+\ell^2} \end{equation} so that \begin{equation} \phi = \int \frac{\ell\,d\lambda}{\lambda^2+\ell^2} = \arctan\left(\frac{\lambda}{\ell}\right) + \alpha \end{equation} where $\alpha$ is an integration constant, and we conclude that \begin{equation} \tan(\phi-\alpha) = \frac{\lambda}{\ell} \label{phipolar} \end{equation}
We can combine ($\ref{rpolar}$) and ($\ref{phipolar}$) to express $r$ in terms of $\phi$, yielding \begin{align} r^2 &= \ell^2 \left( \frac{\lambda^2}{\ell^2}+1 \right) \nonumber\\ &= \ell^2 \left( \tan^2(\phi-\alpha)+1 \right) \nonumber\\ &= \ell^2 \sec^2(\phi-\alpha) \end{align} or in other words \begin{equation} r^2 \cos^2(\phi-\alpha) = \ell^2 \end{equation} so that \begin{equation} r \cos(\phi-\alpha) = \pm \ell \end{equation} where both signs are necessary to preserve the interpretation of $\ell$ as angular momentum (since each curve can be traversed in either direction).
Finally, using the addition formula for cosine results in \begin{equation} r\cos\phi\cos\alpha + r\sin\phi\sin\alpha = \pm \ell \end{equation} which is, not surprisingly, the general form of the equation of a straight line, since $x=r\cos\phi$ and $y=r\sin\phi$.