Use $(whoami) instead of $USER.
The reasons are as follows.
If the environment in which the shell script is executed is not a login shell, the variable $USER may not be set. For example, in a Docker container, an interactive shell is started unless you specify otherwise.
$USER may be overridden, in which case the shell script will not work properly.
Use $(whoami) instead of $USER. The reasons are as follows.