Notice the ‘~$’ right before the ‘xz’ command is called, remove that.
Also I am not sure you would use ‘dd’ to write directly to the mounted disk. I would expect you would to write the device: ‘… -of=/dev/sdxx …’ after you ‘unmount /nvme0n1’
Someone else may weigh in here.