I believe the error is not related to the script at all. The issue is: the directory at which you are when you try to run the script does not exist anymore. for example you have two terminals, cd somedir/
at the first one then mv somedir/ somewhere_else/
at the second one, then try to run whatsoever in the first terminal – you’ll receive this error message.
Please note you’ll get this error even if you re-create directory with the same name because the new directory will have different inode index.
At least this was in my case.