The main issue is that you are hitting a return
before it even reaches your loop.
I've cleaned up your code a bit as well as turned your loop into a hotkey. This will prevent multiple writes to the file if the key is held. If you need to count holding of the button, you can use the loop you had.
FormatTime, timestamp, , yyyy_MM_dd_HH_mm
JoystickNumber = 1
#SingleInstance
#Persistent
InputBox, ssnum, Subject Number, Please enter the participant number
if ErrorLevel
ExitApp
thefilename = C:\%ssnum%_T_%timestamp%.txt
FileAppend, %ssnum%`t%timestamp%`n, %thefilename%
~Joy8::
FormatTime, timestamp, , HH:mm:ss
FileAppend, %timestamp%`n, %thefilename%
Return
q::
MsgBox Exiting. Your data is saved in the C drive as %thefilename%
Run % thefilename
ExitApp