URGENT bug fix: use append mode when writing