Ultraviolet (UV) MSM photodetectors (PD) based on AlGaN alloys find many applications, including flame sensing. In this work we investigate the dependence of AlGaN based photodetectors grown by MBE on the kinetics of growth. MSM photodetectors were fabricated in the interdigitated configuration with Ni/Au contacts having 400 μm finger length and 10 μm finger spacing. Bulk Al0.4Ga0.6N films were grown on to sapphire substrates using an AlN buffer layer. A series of PDs were developed using the Al0.4Ga0.6N films grown under different group III/V flux ratios ranging from stoichiometric conditions to much higher than unity. Upon testing, it was observed that the otherwise identical photodetectors show significant decrease in dark current as AlGaN deposition conditions change from stoichiometric to excess group III, due to reduction of unintentional incorporation of oxygen-related point defects. In addition, the intensity and spectral dependence of the photocurrent also change, showing an extended low energy tail for the former and a sharp and prominent excitonic peak for the latter. The optical transmission measurements indicate a variation in Urbach energy with deposition conditions of the AlGaN films, although they have the same absorption edge. While all samples show a single red-shifted photoluminescence peak at room temperature, upon cooling, multiple higher energy peaks appear in the photoluminescence (PL) spectra, indicating that the alloys contain complex compositional inhomogeneities. Two types of alloy fluctuations, determined by the growth conditions, have been identified that modulate the optoelectronic properties of AlGaN by changing the spatial localization of excitons, thereby altering their stability. We identified that growth under stoichiometric conditions leads to compositional inhomogeneities that play a detrimental role in the operation of MSM photodetectors, which reduces the sharpness of the sensitivity edge, while growth under excess metal conditions enhances it.