Grainy mac and cheese is usually the result of adding cheese to a bubbly mixture, breaking emulsifiers and coagulants in cheese down. Remove mixture from heat before folding in cheese. Add cheese slowly for best results. It can also be caused by using low quality or pre-shredded cheese.