move writing-in-chunks to it's own function as write_targets is getting expansive
move writing-in-chunks to it's own function as write_targets is getting expansive

desihub/desitarget,desihub/desitarget