Refactor: extract writeICalFile