Sam said he transcribed the diary at the Citadel. They left the Citadel immediately after Gilly read that part out loud, so it is possible that Sam is telling the truth and he had transcribed it earlier. Which would also explain why he didn’t react when Gilly read it- he already knew that. Or maybe he just stole her…