document.write is considered to be a bad practice.
For example, when executed after the page has finished loading it will overwrite the page, or write a new page, or not work at all.
The solution may be to use innerHTML method of a DOM element, something like this:
document.getElementById('block').innerHTML = '<b>YO</b>, that works!';
Or DOM manipulation methods http://www.w3schools.com/dom/dom_document.asp