UPDATE
I found out that my webhost's server has both a www and a public_html directory. I've been uploading my site to the public_html directory. I noticed that the www directory has all of the same files as the public_html one. I'm assuming everything gets copied over automatically. Anyway, when I execute the above code, the image is copied to the www directory instead of the public_html one. So, when browsing my site, I do not see the uploaded image because it doesn't exist in the public_html direcotry.
The file still gets moved to the WWW folder even if I go through the root directory: /home/username/public_html/foldername
Hope that makes sense. How do I fix this?