Although small amounts of oxygen were present very soon after life appeared, the significant buildup probably began about two billion years ago. There is evidence that the beginning of the oxygen buildup coincides with the appearance of the first eukaryotic cells. Most bacteria don't require oxygen, and many are poisoned by oxygen. All eukaryotic cells require oxygen for their more complicated and more efficient metabolism. Furthermore, there has to be oxygen for there to be ozone.
Ozone shields the surface of Earth from damaging ultraviolet rays.
Only with such shielding can life come out from under the water and begin to live on land. Chance mutations in the genes of some bacteria enabled them to endure the oxygen atmosphere and rescued them. At the same time a fortunate symbiosis between bacteria and the formerly free-living mitochondria enabled eukaryotes to evolve in response to the crisis. Oxygen-based metabolism came into being. The environment changed and life randomly followed.