To have it work in pm's change the # in the ON TEXT event to an *

Also note that in a pm, your first if statement will always return $false as the # character references a channel name, and in a pm there is no channel name, so the # character returns $null

Regarding the file not being written, it probably is but you reference spam.txt for the file that is read and spams.txt for the file that is written.
Additionally, since you didn't specify a directory location for spam.txt, mIRC looks for that file in the same directory where mirc.ini is located. Your Spams.txt file is specified to be in the logs directory.