I don't know if this will help you, as my touch bar issue wasn't exactly the same as yours, but I just fixed mine by deleting all software/apps/etc related to OneDrive (I have a MacGook Pro 13" M2, running on MacOS Ventura 13.5.1).
As soon as I dragged those to the trash, my touch bar flashing ceased (was only flashing mainly on the left hand side of it), and the windows that kept flashing (selecting/de-selecting) and which would prevent me from typing properly in my main account immediately stopped, no restart required. I had gone to the Apple Store and asked for assistance where the rep created a test user account to see if the issue existed there and it didn't, so was told it was likely a software issue. Then was told to try erasing my Mac and restoring and seeing if that would fix the issue (it didn't); I did this probably 15 times at home. If that didn't work, I was told to try restoring piecemeal, one by one and see if that would work. I narrowed it down to my Applications folder and found the issue was OneDrive.
I had tried 30+ other combinations of things, and restarted numerous times to no avail before I noticed the OneDrive app was not closing no matter how many times I tried to close it after examining the apps that opened at login (searched Login Items at System Settings under Apple icon). So in case that's the root cause of your issue, maybe give that a try.