Return of excess contributions keeps raising MAGI

In 2023 I overcontributed my Roth IRA by $1,190. To rectify this, I asked my provider to return the excess contribution along with $170 worth of gains.

 

Now from what I understand, earnings such as these need to be included in your taxable income for the year the excess contribution was made. If I add the $170 income to my 2023 return, my MAGI increases and my Roth contribution limit is further reduced - creating a situation where I'm still overcontributed.

 

How do I get to that magic number where I withdraw just enough to get under the contribution limit, but not too much to the point that my MAGI goes up and further reduces my allowable limit? It's like a vicious cycle that's giving me quite the headache!