Fix OPEN_MODE_APPEND and add test case