A few things might go wrong in this script.
1) object_id='gID002' may not be a Bandstructure object (I don't know, because I cannot see how file.nc was written).
2) bs_up and bs_dn are arrays with dimensions (#kpoints , #bands), for example (201, 15). When writing to data files, you need to write all bands. The script I posted previously illustrates this.