Cold milk takes much longer to spoil than warm milk. However warm milk is better for recipes and is reputed by folk wisdom to be an excellent sleeping aid.
Food safety standards recommend that milk not in immediate use be stored at a temperature below 45 F. This prevents the growth of dangerous bacteria that could cause the milk to curdle or produce illness in those who drink it. The elderly, infants, pregnant people and anyone with an immune compromised condition such as lupus or HIV are especially vulnerable.
However, when milk is drank immediately after heating, or used in baking recipes, bacterial growth is not a problem. Many people swear by warm milk as a cure for insomnia, but the New York Times notes that this soporific effect is probably just psychological. Milk does contain tryptophan, a neurochemical that promotes sleep, but the protein in milk makes it difficult for the tryptophan to cross the blood-brain barrier. Carbohydrates eaten in combination with milk make it easier for the tryptophan to cross and actually promote sleep.
When baking, warm or at least room temperature milk makes for fluffier cakes. The higher temperature makes it easier for the milk to mix with the other ingredients, producing smoother batters that will trap air and make for a fluffier crumb when baked. Milk should be left out for 30 minutes to 1 hour before baking, but remember to only leave out as much milk as needed for the recipe to prevent spoilage.