backing up a database into a new folder
Why are you reinventing the wheel .. as there is a cost to reinvent it !

You are also using deprecated stuff e.g. sysdatabases .. instead use sys.databases.

You should use -


Ola's backup solution
Minionware's backup solution


Both  are free and are well tested by the community.