I didn't know this:
It all begins with tears – or more precisely the tear film that coats our eyes. Mammalian eyes of the terrestrial variety, whether they're found on the faces of humans, dogs, hedgehogs, or elephants, are coated in a three-layered tear film that allows the eyes to function properly.
(Tears work somewhat differently in marine mammals like dolphins and sea lions.)
Closest to the eye is the glycocalyx layer – a layer made mostly of mucus. It coats the cornea and attracts water, which allows for the even distribution of the second layer: the water-based tear solution. It might be just four micrometres thick – about as thick as a single strand of spider silk – but this layer is very important. It keeps our eyes lubricated and washes away potential infections. Finally, there is an outer layer composed of an oily substance called meibum, which is composed of lipids like fatty acids and cholesterol.
Meibum has evolved to be exquisitely tuned to the mammalian body. At normal human body temperature, it is a clear oily fluid. At just one degree cooler, though, it becomes a white, waxy solid – the familiar eye gunk.
Large flakes of this solid can form during sleep for a couple of reasons. First, the body cools down a bit at night in general, so some of the meibum becomes cool enough that it moves below the melting point and turns solid. Second, according to Australian ophthalmologist Robert G. Linton and colleagues, "sleep relaxes the [muscular] action on the [meibomian] gland
ducts…[which] is sufficient to cause far in excess of the normal to exude onto the lids and eyelash roots during sleep". In other words, our eyes are coated with more meibum than usual at night – and so when that meibum cools we can end up with appreciable amounts of eye gunk.