Common mistake.
str_replace( $what, $to, $buffer );
should be:
$buffer = str_replace( $what, $to, $buffer );
=)
By the way, there is an easier way to read in the file you are reading, just for future reference.
$buffer = join("", file($file));
join(string glue, array arr) takes array arr and makes a string out of it, inserting string glue between each index of the array. file(string filename) makes an array out of filename, each line of the file makes one entry in the array (starting at 0, fyi, not 1.)
HTH.