The effect of carrier localization on stimulated emission (SE) in Al0.35Ga0.65N/Al0.49Ga0.51N quantum wells (QWs) on sapphire substrate was studied under photoexcitation in the edge emission configuration in the temperature range from 8 K to 300 K. The band potential profile responsible for carrier localization was modulated by the variation of QW width and monitored using fitting the experimental temperature dependence of the spontaneous luminescence band width to that obtained by the Monte Carlo simulation of exciton hopping. A faster increase of SE threshold with increasing temperature was observed in narrow QWs and was attributed to deeper carrier localization due to the modulation of quantum confinement energy by well width fluctuations. Meanwhile, delocalized carriers were shown to contribute to the filling of states at the mobility edge, where SE occurs. These results imply that the deep ultraviolet AlGaN/AlGaN laser structures can be optimized in terms of carrier localization effect through the selection of appropriate QW width.