write_unit function

Write unit object into file