Multiple things can cause this:
Check that the winds are off or aligned with the runway. If you have a crosswind, it will push against the tail of your airplane causing it to turn into the wind. You can counter this by using the rudder, but you have to anticipate and not let the plane go too far from the centerline.
Make sure you don't roll too fast on the ground, on takeoff or landing. If you see the plane veer to the side during take off, try to start your rotation for take off a bit earlier, you are most likely going too fast. Same goes for landing, you can either keep the nose wheel off the ground a bit more, or land at a slower speed.
Ease the pressure/weight you put on the nose at high speed. If you put the "stick forward" when taking off or landing, a lot of weight is put on the nose wheel, and like in real life, it can cause damage, bend structures and will result in a loss of control. Try to keep the stick back a little bit to make sure most of the weight is on the main gear instead of the nose wheel.