Optimised writeFileBytes function.