Always shred your own cheese to avoid a grainy mac and cheese. Pre-shredded cheese from the store has a film like cornstarch or potato starch that makes it grainy.
Cook the roux for two to three minutes to avoid a grainy mac and cheese.
When adding cheese to the sauce, reduce the heat to low and add it slowly while mixing to prevent the cheese from curdling.