https://en.wikipedia.org/wiki/Scrotum#Function
Temperature control is accomplished by the smooth muscles of the scrotum moving the testicles either closer to or further away from the abdomen dependent upon the ambient temperature. This is accomplished by the cremaster muscle in the abdomen and the dartos fascia (muscular tissue under the skin).