Stars appear to twinkle because the light from them must reach us by passing through the atmosphere of the earth. By doing this, the light will experience some "distortion" (refraction is the physics term) to a greater or lesser degree.
We see this because of light's passage through layers of air with differing temperatures, pressures, densities, moisture content and other factors. All of them will have a subtle effect on the light, and it will "waver" a bit so that we get a "twinkle" when we look at the stars. Temperature differences are well known for distorting light, and the "heat waves" we see when objects are viewed through air with differing temperatures in the path of the light are things we can generally recall. On a hot day, air above the heated surface of a dark colored vehicle appears to "shimmer" because of the "heat" rising from the vehicle.
Light from the stars came a long way to get here for us to see it, but it is its passage through earth's atmosphere that gives it the greatest difficulty. And we see the difficulty the light has getting through the atmosphere 'cause it just can't stay in a straight line. The small "shifts" the light takes in its travel appear as the "twinkle" of the stars.