Intermittent issues like this are often caused by race conditions with multi-threaded programs.
In Windows, we see this a lot with use of _WINDOWHANDLE at the start of a program. _WindowHandle returns a result, before windows has even finished fully registering and creating the handle, and then all sorts of bad stuff happens when we try and use that invalid handle. Usually, in these cases, the fix is as simple as adding a _DELAY 0.2 after the SCREEN statement and before the call to _WindowHandle to make certain that race condition has time to complete before it glitches out.
For Linux, I don't have a clue where and how it can run into the same situation. My coding anymore is basically just 100% Windows based.
My suggestion would be to try adding a few _Delay statements into your code at various points (especially at initialization) and see if the issue goes away. If so, then you can narrow down on the *exact* line that's causing the glitch, and just add a single _Delay before it and resolve the issue.
Best of luck on finding/fixing the problem. Nothing is worse to debug that a glitch that only appears intermittently!