Grainy caramel sauce is caused by sugar crystallization which can happen when sugar splashes up on the side of the pot. To help prevent this, stir gently. You can also keep a wet pastry brush nearby to remove any sugar that splashes up the side of the pot.