i've now done it the following way, which in my opinnion isn't really efficient, but well, it works anyways:
$headstring = '<?xml version="1.0" encoding="UTF-8"?>';
$fw = fwrite($fd, "$headstring \n");
$fc = fclose($fd);
$fd = fopen("$userfile","a");
$headstring = '<!DOCTYPE product SYSTEM "/usr/local/dtd/product.dtd">';
$fw = fwrite($fd, "$headstring \n");
this way, the new lines are getting written correctly to the file. i just don't see why it doesn't work when you have the \n's directly inside of $headstring.
Emanuel