Selfless good deeds is indeed an interesting topic, one that I have never found adequately discussed in Western thought.
One tradition that seems to take that question most seriously is that of the Malamatiyya, followers of the Path of Blame. They consider that doing good deeds almost inevitably feeds one's ego, the opposite effect to that desired by one pursuing a spiritual path.
I gather that they developed techniques to counter the tendency:
IX. MALÂMATÎ PRINCIPLES
The main principle on which the Malâmatî Path is based requires that one always behold one's self as blameworthy. Rather than being an ethical postulate, this principle stems primarily from a psychological understanding of the nature of the self. The 'self', or more accurately the 'lower self' (nafs), is understood by the Malâmatî mystics as being the tempting element in the psyche, al-nafs al-ammâra bi'l-sû': 'the soul which prods one to evil' and in this capacity it functions as the agent provocateur of Satan, the lusts and all evil inclinations. Yet it is also understood as the centre of ego consciousness. Most mystical systems agree that the more one's energy is absorbed in satisfying and gratifying the requirements of the ego, the less energy can be put into the process of psychological and spiritual transformation...."
https://goldensufi.org/a_ss_malamati.html
I haven't heard of the Malamatiyya before and it was very interesting learning about them!! It makes sense.. By reminding yourself your imperfections and being able to take blame you can get closer to the "higher" self. Although it might look like a "painful" or difficult path, it could work, since you focus less on you -and everything fabulous about you that can be quite destructive..
In Eastern Christianity it is also believed that you should not communicate a good deed with others since there is a temptation to brag about it. Therefore it loses its initial aim..