Fixed ~ expansion bug

In Mac OS X '~' will not expand to the user directory. Instead, a directory by the name of '~' will be created. This patch fixes this issue.