1. The dot '.' is the string concatenation operator. You can't just enclose the whole lot in 1 set of quotes, it won't interpolate the POST vars correctly.
2. you're nearly there, but you need to add '.' after each newline ("\n"), or print to the tgt file as separate strings.
you may find this link useful: defnitions of entire lang + lots of examples:
http://www.php.net/manual/en/
HTH