Oh, that's interesting. The glitch frame you are seeing is that occasionally for 1 frame you're using the wrong CHR pattern page for your nametables.
This is controlled by
bit 4 of the register at $2000. Once every several frames your code is writing $80 instead of $90 to this register, which causes it to select the $0000 CHR page for backgrounds instead of the $1000 page you want.
I don't know how this is being triggered, or why it doesn't happen every frame. The code is a LDA #$80, STA $2000, which I can't find in the neslib.s source
found here. Maybe shiru can answer your question.
However, the code you have written is still a problem. You should only turn the PPU off when you need to take rendering down for multiple frames so you can place a lot of data into the PPU. For an update that happens every frame,
do not turn the PPU off, just push the data through with set_vram_update. You should be able to push at least 32 bytes per frame through there, if not more (I don't use shiru's neslib, so I can't tell you its performance limits).
Edit: oh, didn't see your comment about delay(), I was going by your pastebin source. That explains why it's not every frame at least. I expect the offending write to $2000 is in ppu_on_all, but I also think you are probably using an out of date neslib? Try using the one at shiru's page instead.