Milk curdles when stored improperly due to the growth of bacteria that produce lactic acid, which lowers the pH and causes the milk proteins (casein) to coagulate. This process is accelerated at warmer temperatures.
Milk contains natural bacteria. When milk is stored at room temperature or above, these bacteria multiply rapidly. Many of these bacteria consume lactose (milk sugar) and produce lactic acid as a byproduct. The increase in lactic acid lowers the pH of the milk, making it more acidic.
Milk proteins, primarily casein, are stable at the normal pH of fresh milk. However, as the pH decreases due to the lactic acid, the casein proteins become destabilized. They begin to clump together, or coagulate, forming visible curds. This process is known as curdling.
Refrigeration slows down the growth of bacteria, thus slowing down the production of lactic acid and preventing curdling for a longer period. Improper storage, such as leaving milk out at room temperature, provides an ideal environment for bacterial growth and rapid curdling.
Store milk in the coldest part of your refrigerator, typically on a shelf rather than in the door, as the temperature in the door fluctuates more frequently.