Atmosphere covers the Earth, like a blanket. We know that air is a bad conductor of heat. The atmosphere keeps the average temperature of the Earth fairly steady during the day and even during the course of the whole year.
The atmosphere prevents the sudden increase in temperature during the daylight hours. And during the night, it slows down the escape of heat into outer space.
The moon, which is about the same distance from the Sun that the Earth is, with no atmosphere, the temperature ranges from –190º C to 110º C.