I'm wondering if you extended the delay statements to 2000 and perhaps added one after the wget ifthis would make any difference. Possibly you might put a wprint statement like wprint "screen cleared. :" after your cls.
I may be wrong, but i look on wprint and cls as doing things to a buffer inside tbe esp, and wait or returngui as pushing them to the browser. If that were so, then you issue a cls, followed bh a wait, screen clears. Issue wprint, commanx is stacked. A new cls is issued before that is printed. And so on. Serialprint is simpler , i think that just goes as soon as you issje the command.
For debugging, if youre doing it using some form of command the displays data, i've found ituseful to display each steps variables and also put smething either side to show blank values....