Use fchdir when available

Exactly what it says on the tin.