You can create/open a new file then write in it the concatenation of your variables:
$scores_file="scores.txt";
// open the file
$handle = fopen($scores_file, 'w') or die('Cannot open file: '.$scores_file);
// create 1rst line and a line feed \n
$data="Number of guesses:".$_SESSION['antal_gaet']."\n";
// concat the 2nd line
$data .= 'Username:'.$_SESSION['username'];
// write to the opened file
fwrite($handle, $data);
1
solved How to send info from two session variable to a text file if a number has been guessed [closed]