UPDATE:
fgets() function reads only 1 line at the time, and by putting that line in your $content variable, you're overwriting the replacement for previous line, and doing it over and over again.
Try with this:
$content = "";
while(!feof($bodyfile)) {
$line = @fgets($bodyfile);
$content .= str_replace("MARGIN","",$line);
So, what this code does is reading the line and assigning it to the $line variable, and then adding the replaced string to your $content variable.
By adding @ sign in front of your functions, you're suppressing errors which that function gives.
Try to remove @ from your @fgets and see if there's any error.
Try var_dump($content) or echo $content to see if file is loaded correctly.
Remember that str_replace() is case sensitive.
$contentlook like ??str_replaceis case-sensitive!str_ireplaceis not!