Interesting, so basically reverse a few lines and it should work?
var divToInsert = document.createElement('div');
var page_content = document.getElementById("page");
page_content.appendChild(divToInsert);
divToInsert.setAttribute('id', 'layer');
hmm - something tells me IE won’t like adjusting the ID of an element once it’s on the page. Maybe try to use “class” instead of “id” if you have more problems.