Stars twinkle because
the intensity of light emitted by them changes with time
the distance of the stars from the earth changes with time
the refractive index of the different layers of the earths atmosphere changes continuously, consequently the position of the image of a start changes with time
the light from the star is scattered by the dust particles and air molecules in the earths atmosphere