I’ve been looking on Google and I searched on SO for the answer, but I can’t find anything.
The document.write function seems pretty useless because it replaces the previous contents. Does it accept any arguments, or is there a legitimate use for it?
Documentation can be found at MDN. It only replaces the content if you call it after the document was parsed.
If it is called during parsing, then the content is just inserted. Quite a few scripts use this, so that you just have to copy and paste them in your HTML where you want to have the output, without any further actions required from your side.
Its usage is not undisputed though, because of what you already mentioned: If you use it at the wrong time, all the content is erased. Furthermore, it is not available in XHTML documents.
But IMO it’s the same with many other things: If you are aware of the difficulties/drawbacks and know when to use it, then it’s ok to use it.