A question I pondered; an answer the Internet gave:

Sleep as such is a mental process that allows the brain to process recent information onto memory. Reviewing this information sometimes out of order is the reason for dreams, and since if it was otherwise, acting on a dream while asleep could be dangerous in the absence of active awareness, the REM sleep that is associated with dreams also comes with primary motor paralysis.
Since learning (and the intellectual activity associated with this learning capability) is essentially non existent in a creature as simple as a fly, those animals do not sleep per se.
During night, due to the lower temperature, they may get in a state of torpor, lacking the energy to move. Also, since flies are diurnal animals, they would lack the vision acuity to navigate at night and so stay put. They find themselves a cozy spot, and stay there until daybreak.