There are a couple of things that could be causing this issue. The first is overcooking. If you add cubes of cheese instead of grating it, it will take longer to melt. In the meantime, your milk has a higher probability of curdling due to overcooking. So while it looks like your cheese isn’t melting, it’s really the milk that has been ruined and the cheese hasn’t had enough time over the heat.