Well, you know how to get the data from your database, right?
All you need to do then is to add all the data to one string, like
$data="";
yourdatabaseloop
$data.="<$data1><$data2><$data1>\n";
yourdatabaseloopend
and then you save this to a .txt file,
$filelocation="mytext.txt";
$newfile = fopen($filelocation,"w+");
fwrite($newfile, $data);
fclose($newfile);
this will try to create a file called mytext.txt and write the data to it.
However if you directory does not allow it, it fails, so you should create the file manually and set its attributes so the script can write to it. via chmod 666
Hope this helps,
Chris