When you change the temperature of any material, the material also changes size. If you apply heat to an object, it will get bigger because the heat energy makes the molecules move around faster, and they spread out a bit. Cooling an object will shrink it due to the same but of physics operating in the opposite direction.
In the case of trying to separate two objects that are close together, you should apply heat. In the case of the stopper in the bottle, warming the neck of the bottle will make it a little looser, and the stopper should come free. Even if the stopper gets warm and expands, this usually still works because the space between the two increases slightly in size as well.This is also true for loosening metal screws and other fasteners.
If the stopper is really stuck, heat the neck of the bottle, and then cool the top of the stopper. You should be very careful when doing this because rapid temperature changes can cause the glass to experience thermal shock and shatter.