You don't have to write the data to a file, PHP does that for you.
Just make your links like this:
Outside a PHP code block:
To continue, <A HREF="nextpage.php?<?=SID?>">click here</A>
Inside a php block:
print "<a href=nextpage.php?".SID.">link</a>";
That will pass the SessionID of the currently started sesion to the next script.