Mysql >> Php >> Xml

I have all the connections working etc but i cant get my PHP script to make a new .XML file

Can anyone see whats wrong?

$sql = "SELECT * FROM apris"; 
    $result=mysql_query($sql) or die("query failed: $sql - ". mysql_error()); 
    $filename = "apris.xml";
    while($line = mysql_fetch_assoc($result)){
        $fp = fopen($filename, "w");

        fwrite($fp, $line);

        fclose($fp);}