Why i can't use fwrite() and fputs() functions

CODE
$counter = 0;
while ($counter < count($ctup))
{
list($assid,$clubname) = explode(":",$ctup[$counter]);

$www2 = file_get_contents('http://ru.uefa.com/footballeurope/countries/association='.$assid.'/standings.html');
$www2 = str_replace("<td>", "<td align='center'>\n", $www2);
$www2 = str_replace("<tr>", "<tr class='lgheading'>\n", $www2);
$www2 = str_replace("</th>", "</th>\n", $www2);
$www2 = str_replace("</td>", "</td>\n", $www2);
$www2 = str_replace("</tr>", "</tr>\n", $www2);

$begin = strpos($www2,'<table class="tableStandings">');
$endl = strpos($www2,'</table>'); // находим конец


$leaguefile = fopen("comp/modules/league/leagues/$clubname.html", "w+");

for($i=$begin;$i<$endl;$i++)
{
fwrite ($leaguefile, $www2[$i]);
}

fclose($leaguefile);

$counter++;
}


This code is not work