CORE: A Retrieve-then-Edit Framework for Counterfactual Data Generation