I think you were close with the $output thing, you should just be able to replace each echo with "$output .=", like
Code:
$output .= "<b>Vcash Leaderboard</center></b><br><br>";
You'll also need to change the part where you use ?> and <? around some html to be a string constant instead, and then assign it to $output the same way, like
Code:
$output .= "<tr><td>$rank$username</td>
<td>$" . ROUND($ucash) . "</td> </tr>";
If you had a lot of code you could also surround it with ob_start() and ob_end_clean() to buffer the output, but you only have a few lines so you might as well make the changes to assign to $output.