unset($conf); here as well to help on memory consumtion.
Also why not file_put_contents()?