After trying a lot of approaches with observing random JSESSION id being generated, We tried cleaning IE cookies, IE History, IE temp files but did nothing to resolve it.
We observed that whenever we had Internet Explorer Developer Tools (F12) opened, the script worked fine.
Finally we tried removing the following line from the javascript
console.log('loaded');
and the script started working fine.
So to Summarize:
Calling any method on Console object interferes with normal Script execution when Internet Explorer Developer Tools is not running