I've already fixed this locally. The culprit is the last sleep(0.01). Presumably this is too fast, not allowing the function to catch up properly.
A sleep value of 0.02 or higher fixes this issue entirely, however the text will appear to "lag" behind. A middle-ground value such as 0.015 appeared unusable during testing, so the end result procuded slight lag, but it wasn't very significant.