When is document.write OK?
There are many places where programmers are advised to avoid document.write (even the HTML5 specification gives it a hard slap in the face), which is good because it is one of those rather clumsy things that were introduced at the very beginning of web scripts that were never standardized or were not even indicated and were replaced by other methods.
However, there is at least one other case where it can be considered useful.
User agents that do not support scripting
Many web pages have hundreds of kb scripts, mainly because developers simply drop libraries and plugins, not paying attention to page size, because it saves several hours on development, and developers consider their time more important than the time of their client or visitors - employers.
Browsers will usually not load scripts if scripts are disabled or unavailable, but some may. Using a script to insert scripts means that if scripts are not available, script elements are never placed in the document, and related resources are never loaded.
document.write is a very simple way to implement a script loader. Of course, there are much more complex script loaders to do the same, but the good old document.write is dead, works everywhere and for this purpose does the job perfectly with the same ease as innerHTML.
And given the widespread use of innerHTML (and even markup fragments as a method of creating elements using DOM methods), it seems reasonable to use a similar tool to insert scripts.
If insert using innerHTML does not work
This is almost the same as above, but slightly different.
Script elements inserted with innerHTML are not executed, so if the document stream is open, it is quite simple to use document.write instead of innerHTML. The usual caveat applies, however, using document.write after loading the document, first delete the current document, which is not always (preferably, almost never) desirable.
Popup windows
Well, everyone hates pop-ups and combining them with document.write seems the worst of the worst of the worst. But sometimes a simple pop-up menu with document.write text is simpler and faster (both for development and presentation) than more complex dialogs.
XHTML Apology
document.write does not work in documents other than HTML (e.g. XML). But while many pages on the Internet have XHTML DOCTYPE (perhaps because CMSs prefer XML over HTML), the pages almost always serve as text / HTML, so the browser views them. It is highly unlikely that in the near future the web will move to XML (that is, documents actually used as XML). For web pages, DOCTYPE is essentially the flag used by the browser for development if it should be in standard mode or not, so the XML thing is a bit of Phurphy.
However, the bottom line is that document.write almost never be used "in the real world," because the DOM methods provide a standardized alternative, have well-defined behavior, and are almost universally supported. document.write more or less equivalent to eval in that there are some rare cases where this is useful, but there is almost always a better way to do something.