The cremaster muscle. It is inside of the scrotum and extends into the groin. It pulls the testicles up towards a man's body when cold ("shrinkage" for all you Seinfeld fans!) and lets them hang more free when hot thereby ensuring the proper temperature for successful and healthy sperm production.
Another little known purpose is it controls testicular contractions during a man's orgasm. As a man near orgasm, it draws the testicles up close. If you or your partner pull them away as you get close to orgasm, it will slightly delay your ejaculation and increase your orgasm's intensity.