When it comes to animal intelligence, I think it's far too easy to anthropomorphize creatures which we have no solid reason to. I don't know what my cat, a fellow mammal, is thinking, let alone what an insect is thinking.

***
Moths and flames:
Almost all the reference material says that bit about moonlight is what's going on and talks about transverse orientation to celestial bodies as a common guidance method for migratory animals.

This article, interestingly, debunks a lot of hypotheses
TL;DR
A) Navigation by moonlight or starlight is almost unheard of in non-migratory animals. Over 50% of moth species are non-migratory.
New research suggests (at least some) migratory birds can sense the Earth's magnetic field, and do not navigate by moonlight.
B) Artificial light sources have been around for over 400,000 years in the form of campfires. The hypothesis that moths have failed to adequately evolve to understand and deal with modern light sources is thin.*
C) There was a hypothesis that female moth's hormones emit light, and that male moths were confusing fire light for steamy females. However, the emission spectrum of a campfire is very different from the spectrum of female moth hormones.

*However, 400,000 years isn't really that long on an evolutionary scale and if the young and virile moths aren't killing themselves, then it wont be selectively bred out of the species. Natural selection is only concerned with survival of the most fit reproducers. Any disease or affliction that affects a being after it has produced offspring is that being's own problem.

In conclusion: We don't know what's up with moths and their kamikaze behavior.