Asta nu mai e o problema de newline.
Tu folosesti "fopen ($filename, "w")". "w" inseamna:
"Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it."
Tu vrei sa deschizi cu "a" (sau "a+"):
"Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. In this mode, fseek()() only affects the reading position, writes are always appended".
http://php.net/manual/en/function.fopen.php - vezi parametrul "mode".
PS: Foloseste sprintf, sa para mai lizibil:
sprintf("A venit o vizita din partea: %s , cu IP-ul: %s\n\r", $ref, $ip);
PPS: Sper ca nu folosesti "PHP_E0L" ci "PHP_EOL".
Da codul si erorile data viitoare.