Write files in append mode when appropriate