moving write header in init_encoder

RCWT header can't have a BOM before it, or parsing it later will not
be possible