Insects are attracted to artificial lights, especially porch lights, because they cannot discern artificial light from moonlight. Most bugs have evolved to travel by moonlight, and they are able to keep an even path by having moonlight at a steady angle relative to their position.
When flying insects get close to an artificial light, they try to use the light as a guide instead. However, since artificial light shines light on all sides, insects get confused and continuously fly around the light fixture. The interference that artificial light imposes on the navigation of insects is believed to have diminished the population of some insect species.