A suggestion from personal experience:
confession is a big help.
Now, what I mean by that is not strictly the Catholics' sacramental confession but confession in general (though I feel that may be just as helpful).
I decided at the start of the year that this would be NN2022. I told some beloved friends of mine I had been having this problem and that I would be taking up this task. I have not succeeded in that goal. I failed twice in January and twice in February. Each time, I wrote the date down in a .txt file and told one or more of my friends about it.
Now, in addition to every other motivation, I have the additional motivation that I do not want to let down my beloved friends.
There was one day, more recently, that I spent an amount of time looking at stuff I ought not have been looking at. That night, when I lay in bed, I was unable to control my thoughts. I sent a message to my friend and asked him to pray for me. I told him that, if he prayed for me, I would not fail that night. after what felt like hours, I managed to fall peacefully asleep.
tl;dr tell your loved ones about your problem and hold yourself accountable not just to yourself but also to them
>Confess therefore your sins one to another: and pray one for another, that you may be saved. For the continual prayer of a just man availeth much.