To prevent the rosti from falling apart while cooking, make sure to squeeze out a good amount of water from the grated potato and mix it well with the egg and flour, which helps bind it together.