Use cache directory when downloading composer.phar

Since there is a cache dir there is no need to populate the project
directory with temp files. Plus the permissions on the project dir
might not allow that.
Check if current dir is writable and if not try the cache dir from settings
Cache path never ends with '/'
Merge remote-tracking branch 'jimmykane/master'