You are building the target path using the complete source path appended to your home directory. But
imagemagick will not create non-existing directories but expects them to exist already (background: it just tries to create the file using a file open function that fails when the directory does not exist).
So you have two options:
- Create the directory
dirname($source)
below your home directory before executing imagemagick, or - Use another existing directory to store the converted file.