No, in general, they don't close. (Though, as you say, some geodesics do.) Consider, for example, an oblate ellipsoid of revolution, and take two points on its equator such that the angle $\alpha$ between them is not a rational multiple of $\pi$. On a sphere, the only geodesic passing through tho points on the equator is the equator; but in our case, since the ellipsoid is oblate, if $\alpha$ is large enough (i.e., close enough to $\pi$), then there are shorter paths connecting the two points, so there are other geodesics passing through the two points. If we take one of these geodesics — let's say the one going through the northern hemisphere — and continue it past one of the two points into the southern hemisphere, it will behave symmetrically there and intersect the equator after another angle $\alpha$. And then after another $\alpha$, and so on. Since $\alpha$ is not a rational multiple of $\pi$, there will be infinitely many points where this geodesic intesects the equator, so it will never close.