Check write permissions before writing .nrepl-port

Fixes #1664