Reworked RemoveBom to use unsigned chars and reverted the logic changes in WriteFile. Should work fine now.