Check write permissions before writing .nrepl-port

Fixes #1664
Merge pull request #1766 from ernestas/check-for-write-permissions

Check write permissions before writing .nrepl-port