It could be because the roux might be overcooked or burnt. Be careful about the heat and cook time while making it. Also, remember to add the dairy slowly and stir it constantly. Another reason could be the cheese itself. Make sure to use freshly grated cheese. The heat should be low when you add that, or the texture will be grainy instead of smooth. For convenience, add cheese in batches.