Original: The common names of true flies are written as two words, e.g., crane fly, robber fly, bee fly, moth fly, fruit fly. The common names of non-dipteran insects that have "fly" in their name are written as one word, e.g., butterfly, stonefly, dragonfly, scorpionfly, sawfly, caddisfly, whitefly.
Simplified: Some insects have the word fly in their names, but they are not flies at all.