The standard answer is that moths aren't attracted to bright lights, they're confused by them. Many species of moths migrate and they use the Moon as a navigational cue. Then, humans come along with artificial lights, which appear brighter than the Moon and those become the moths' point of reference, instead. By this theory, the moths don't even mean to end up at the light. They're just trying to maintain a constant angle of flight relative to it. But, because they keep getting closer, that angle keeps changing until, BAM!, they run into their artificial moon.
Trouble is, there are a lot of holes in that theory. Not all the moths that are attracted to lights are migratory, for one thing. For another, there are studies showing moths beelining for the light, rather than spiraling towards it, as you'd expect if the effect could be explained by navigational error. So why head towards the light? Other theories include: An attempt to get a better look at the surrounding area for places to hide from predators; a case of mistaken identity where male moths confuse the spectrum of light for that produced by female moth pheromones; and a different case of mistaken identity where the moths confuse artificial light for night-blooming flowers. All those theories have holes, though. So the ultimate answer seems to be that we still don't know why moths head towards the light. Maybe you can do the research and figure it out.
Maggie Koerth-Baker is the science editor at BoingBoing.net. She writes a monthly column for The New York Times Magazine and is the author of Before the Lights Go Out, a book about electricity, infrastructure, and the future of energy. You can find Maggie on Twitter and Facebook.