The PHP may not have read/write permissions for your file. If you didn't it would probably throw some kind of error, but depending on the context you may not see it (eg via AJAX). Try outputing some values (ie the return values for fopen, fwrite and fclose) and maybe making the code a bit more robust by throwing in some ifs like
$test_var = is_readable("datalog.txt");
echo "Is Readable: ".$test_var;
$handle = fopen("datalog.txt","a");
echo "File is ".$handle;
if($handle !== FALSE)
//print stuff to file
$test_var = fclose($handle);
echo "File Close: ".$test_var;
Something like that should help you trace the source of your error. I'm assuming the text file is in same folder as the php file, otherwise you have to specify the location more specifically.
Just a side note, because of the carriage return with the newline character I'm assuming you're processing this file on a windows system?