Fix write_file on FreeBSD

[SeeRM #8083]
Use fixed `write_file` instead of re-implementing
Land #2026, @egypt's patch for write_file on freebsd