I would suggest investing in a book such as the one found on
http://www.phptown.com/
It's the purple one. It's wonderful. Now, about your question... you're going to have to use fopen(), if I recall, like this...
$fp = fopen("result.txt", "rw");
where $fp is the pointer you want to aim at the file. There's more help on fopen here:
http://www.php.net/manual/en/function.fopen.php
Then you use fwrite() like this:
fwrite($fp, $name);
Most help on fwrite is available here:
http://www.php.net/manual/en/function.fwrite.php
There are a few slightly sticky points to this whole thing, so be sure to read those pages I sent you to. Good luck with whatever it is you're doing.