If the document is not open for recording, the call document.writewill automatically call document.open.
At the first call, the document.writebrowser downloaded the document and, thus, closed it for recording. This calls document.open, which wipes the existing document and creates a new one for writing.
, , docment.write. document.close document.open, .
. https://developer.mozilla.org/en/document.write.