Surely, in the days before man invented artificial light, moths would have been attracted to the only light source at night - the moon. Wouldn't they have just kept on flying until they dropped from exhaustion? In fact does this not happen today in sparsely populated areas, where the moon is still the only night-light available?
Sorry to disappoint you, but there is no concrete answer - only theories. The prevailing theory of the moment is that many moths do not directly fly to light - and therefore wouldn't try to make a trek to the moon. No, what they do is use the moon as a navigational aid. If you wanted to keep moving in one direction and the moon was your only reference point, you would keep the moon at a particular angle to your direction of travel. For instance, you may keep the moon at 45 degrees to your left, and as the moon is relatively static in the sky, you would be sure to travel in the same direction.
"The Moon Just Moved!"
Now, to a moth, with its poor eyesight and fairly simply outlook on life, a street lamp that is only 3 feet away may look pretty much like the vast moon that is thousands of miles away. I guess that moths have never heard of the term "perspective". So, the moth makes its way past the lamp only to find that angle of the lamp is changing rapidly. So it corrects its flight to try to keep the lamp to its left. Just as it does so, the lamp has moved again? and so the moth just circles around the lamp.
The above covers the "circling" moths. There are, however, other species of moth that fly directly to light. I have not uncovered any accepted theories about this (please email me if you have any!). One possible explanation is that the moon is once again used as a navigational aid, but this time these "direct flyers" simply keep the moon in front of them in order to fly in a straight line. As there is no prospect of bumping into the moon this is as good a way as any to travel forwards. Remember that a moth's main purpose in life is to mate - and not to mate with the moon - so they would only use this navigational aid for limited journeys (until they found a mate). How are they to know that what they thought was the moon is actually a street lamp ? no wonder a collision is inevitable!
General Moth Information
There are numerous species of moth and they can be a problem for stored food products, mainly through the risk of foreign bodies. Most moths are attracted to ultra violet light, although green light is often an even stronger attractant.
More information about moths can be found here.
If you just think that moths are a nuisance you may want to look here for an insectocutor