Why it happens
Cheese is made of milk proteins, fat and water held together. When cheese gets too hot, the proteins tighten and clump together, squeezing out the fat, so the sauce turns grainy and oily. Aged, hard cheeses are more prone to this than younger, softer ones. Ready-grated cheese can also give a gritty texture because it is coated with starch to stop it sticking. Adding all the cheese at once, or boiling the sauce after the cheese goes in, makes it more likely.