Stars do not really twinkle. They just appear to twinkle when seen from the ground.
As Christian already pointed out, it is due to the effects of our atmosphere. The light must pass through layers of Earth's atmosphere that vary in temperature and density. It causes that the light from the star is refracted in many different directions.
Because you need an atmosphere to make the stars twinkle, in space there is no twinkling. This is one of the reasons the Hubble telescope is so successful as a much better image can be obtained.