You're correct, it hasn't been added because it doesn't exist. It's being interpreted as a variable name and even if you define it outside the scriptblock the variable won't exist on the machine that's executing the scriptblock. You'll have to pass the variable as a parameter into the scriptblock.
On the other hand, if your intention was to have a literal "$1" written to the file, then escape the "$" character in the scriptblock.