actual browser may rewrite invalid html (and, writing elements outside is not really natural) . You can add an other surrounding div#id and use it to append correctly.
Try this (I also added quotes for element' ids):
<html>
<head>
<script>
</script>
<style>
</style>
</head>
<body>
<div id="main">
<div id="div1" style="border:5px solid green" onClick="alert(this.id)">hi
<div id="div2" style="border:2px solid yellow">hello</div>
<div id="div3" style="border:2px solid red">world</div>
</div>
</div>
<button onClick="document.getElementById('main').appendChild(document.getElementById('div1').cloneNode(true));">cloneNode</button>
</body>
</html>