Writing and Appending to a File with fwrite

Writing to test2.txt
Appending to test2.txt
$filename = "test2.txt";

$fp = fopen( $filename, "w" ) or die("Couldn't open $filename");

print "Writing to $filename<br />";
$aday = date("D d M Y g:i A");
fwrite( $fp, "Hello World\n");
fclose( $fp );

print "$Appending to $filename<br />";

$fp = fopen( $filename, "a" ) or die("Couldn't open $filename");
fputs( $fp, "and another thing\n";
fclose( $fp );