Earth is attracted to sun...its true. But earth is not attracted only to the sun.
Well, by newtons laws of gravity, all objects attract each other, and the force of attraction is propotional to mass and inversely to square of distances.
Now, sun attracts earth. Ok. But what about all the other planets, stars, meteorites, etc?
All of them attract earth too. There are stars millions of times larger than sun, but much far away from earth. They also attract earth. But, sun being the nearest and biggest, excert considererably large force, on its own.
But, again, sun is not the only one here, as told above there are millions of others. So in between this pull by sun to inside, and pull by others to differnt directions, we have a path, where net forces cancel out and become zero. When you plot such a path for earth, you get an elliptical path around sun.
Why elliptical? Because, as I told earlier, there are millions of other cosmic objects, and all of them attract differently, based on their distance from earth. So the path cannot be circular.
Why around sun? As, sun is nearest and hence produce maximum attraction.
So, the earth follows this elliptical path, as the net force is zero. So, no work is done or spent for this movement. Such a path is called equipotential path, meaning potential differnce is zero, so work is zero.
So, reason for this elliptical movement is equilibrium. No one likes stress. So, earth, prevent thw stress ( attractive push and pull) by moving in an equipotential path, here an ellipse.
Scientists have discovered equations to relate to this phenomenon , and hence, find optimum velocities and entry lengths to launch satellites. The satellites also move in these elliptical paths.