Código:
<?php
//ob_start("convierte_caracteres_especiales");
ob_start();
?>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Prueba</title>
</head>
<body>
<?php
echo "<h2>Hola Mundo!!</h2>"."<br />";
echo "<div>Hola!!!</div>";
?>
</body>
</html>
<?php
//inicio el buffer de salida
function convierte_caracteres_especiales($buffer) {
//return htmlentities($buffer);
return $buffer;
}
$html=ob_get_contents();
ob_end_flush();
$myFile="newHTML.html";
$create= fopen($myFile, 'w') or die ("El archivo no se pudo crear");
$contentFile=$html;
fwrite($create, $contentFile);
fclose($create);
?>


