Split a data file into files for each time step
IO operations

Your code for each line of "DEPTH.dat" first open file in append mode, next write one line and finally close file. You may reduce open() and close() calls only to lines when 'SCALAR' line appears.

def split_less_io_operations(src_filename):
    idx = 1
    with open(src_filename, 'r') as inp:
        outfile = open("TS_before_first_SCALAR.dat", 'w')
        for line in inp:
            if line.startswith('SCALAR'):
                outfile.close()
                outfile = open("TS_{}.dat".format(idx), 'w')
                idx += 1
            outfile.write(line)
        outfile.close()


if __name__ == "__main__":
    split_less_io_operations('DEPTH.dat')