I see some issues with the logic around which file you are copying.
Code:
find $HOME -name "$filename"
The above will look below the users home directory for any file matching that stored in 'filename' variable.
Assuming the above returns true you submit the following:
Code:
cp "$filename" $HOME/scripts
Now, unlike the find command, this command shows the 'filename' supplied will be in the current directory (which I might add does not have to be within the HOME directory).
To provide an example and assume we are running from the HOME directory:
Code:
HOME-file1
-file2
-dir1-filename
-scripts
With the above structure, the find would return that it found your filename value but the cp would error as there is no filename in the HOME directory to copy.
Also, have you considered the case where there are multiple files under different directories all with the same name? Again, your find will say it found at least one (in fact all), but again
you have no confidence it will be the one in the top level HOME directory, assuming there is one there at all.
Final note, you create a 'directory' variable but never use it