ho risolto cosi:

$exp = "SELECT * FROM tabella";
$datafile = date('dmYHis');
$mypath = '/home/deposito/';
$file =@fopen($mypath.$datafile.'.txt', 'w');
foreach ($exp as $fexport)

{
@fwrite($file, $fexport[0]."\r\n");
}

fclose($file);
}