Update: I am surprised but your example does actually work with output buffering. I did not think that HTML between php tags would work but it does.
<?php
ob_start();
?>
Hello World
<?php
echo "Goodbye";
$test = ob_get_contents(); ob_end_clean(); echo "output:".$test;
?>
This outputs output: Hello World Goodbye
.
The problem is you are echoing ob_get_contents into the buffer. As your question in the comments was about templating, I still think you are going about output buffering wrong. You should push PHP variables into an HTML template, not pull an HTML template into a PHP script. You should also look into a controller/view solution but below is a basic example.
Templating: For templating, a basic example could be:
<?php
ob_start();
...PHP LOGIC HERE...
...PHP LOGIC HERE...
...PHP LOGIC HERE...
$content = ob_get_contents();
ob_end_clean();
?>
<html>
<body>
<div><?php echo $content; ?></div>
</body></html>