Leaving a plain text password in any file is always a bad idea in case your system is ever compromised. Sometimes it is unavoidable. To make this "secure" you should limit this activity to a very limited user and also leave these sensitive options in a defaults file.
To solve your issue specifically, from the
mysql man page:
If you use the short option form (-p), you cannot have a space
between the option and the password. If you omit the password
value following the --password or -p option on the command line,
mysql prompts for one.
in order to fix this you would need to run:
mysqldump -u [username] -p[password] [db_name] > [path to backup file]
mysqldump -u [username] -password=[password] [db_name] > [path to backup file]