I fixed the problem. It turns out that the cartridge in that shower and the cartridge in another bathroom that I am not using at the moment were bad. I have now learned that even a bad Moen cartridge at a different location from the one experiencing temperature irregularities can be the culprit as it will allow cross flow of hot and cold water even if it is not being used. A guy at the hardware store gave me the trick to see if the Moen cartridge needs replacing:
Run the hot and then cold water on the faucet you are testing to heat/cool the hot/cold pipes. Turn that faucet off. With your hands on the pipes you just heated/cooled, have someone flush a toilet or turn on cold water. if you feel the cold pipe get warm (or the hot pipe get cold) right away, then the cartridge at that faucet is bad. It is allowing the cold and hot water to pass across the valve when the pressure on the hot or cold side goes down. This can lead to cold showers in another part of the house. You don’t notice it with the sink since the pressure drop when the faucet is turned on is less than in a shower.