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:
<html>
<div id="block"></div>
<script>
document.getElementById('block').innerHTML = '<b>YO</b>, that works!';
</script>
</html>
Or DOM manipulation methods http://www.w3schools.com/dom/dom_document.asp