ereg_replace() returns the formatted string, so changing your line from:
ereg_replace("<replaceflag>",$replacestring,$fcontents);
to
$fcontents = ereg_replace("<replaceflag>",$replacestring,$fcontents);
Should do the trick.
Also, on a side note. Because you aren't doing any regular expression matching, I recommend simply using str_replace(). It'll be faster and cause less problems.
$fcontents = str_replace("<replaceflag>",$replacestring,$fcontents);
Hope this helps,
-Josh B