[search] only write last_written_id file if records were updated