Black rectangles in menu bar that randomly appear
To start with I would boot your Mac into Safe Mode and determine if the rectangles still appear.
Booting into Safe Mode on an M1 Mac
Follow these steps to boot your Mac into Safe Mode:

Fully shut down your Mac
Press the power button to start your Mac, but continue holding it down as your Mac starts up until you see the startup options window:



Select your startup disk, press and hold the shift key and click the Continue in Safe option
Let go of the shift key
Log into your Mac (Note: you may need to do this twice)
Take a note of what happens (i.e. do the rectangles still appear while in Safe Mode?)
Exit Safe Mode by restarting your Mac as normal
Test again to see if the rectangles still appear when booted normally

Once you've followed the above steps, let me know how you went and we'll go from there.