What is the difference between 吾 and 我 in 文言文？ For instance, in the phrase 「我善养吾浩然之气」

I notice both 我 and 吾 are used. Is there a reason for this?
The first thing to point out is that「吾」(Baxter-Sagart: /*ŋˤa/) and「我」(Baxter-Sagart: /*ŋˤajʔ/) are cognate. They mean exactly the same thing, and were interchangeable to a very large degree; as the comment pointed out, the use of one over the other is due to either personal preference, emulation of ancient texts, or to avoid repetition.

Specifically in the pre-Qin era, there was some difference in their usage that eventually disappeared by Middle Chinese.「吾」could not be used in the pre-Qin era as an object after a verb. Quote from Zhuangzi:


  《莊子・齊物論》子綦曰：「偃，不亦善乎而問之也！今者吾喪我，汝知之乎？」
  
  子綦 said: "偃, it is very good that you asked this question! I had just lost myself now, but how should you know the answer?"


「吾喪我」could not be written as「我喪吾」in this era.