write to file workiking as unsigned char*