First, make a file in a directory the webserver has access to.
call it log.txt
make sure the permissions are set right (
to be sure; give all with chmod 777 log.txt,
just to test°)
in the script you need to first open the file
$file = "/usr/local/.../log.txt";
$p = fopen("$file","rw+");
the rw+ is the permissions will require ,
you can look these up in the manual.
now read the first line (and put the pointer there too)
$line = fgets($p,filesize("$file"));
and then you write to this line
$write = fwrite($p,$thevariabletoadd,,filesize ("$file"));
this is probably not the best or most efficient way, but it should work.
Hope it helps