random will not give you exactly half each time. If you flip a coin 10 times, you dont necessarily get 5 heads and 5 tails.
One approach would be to use the partitioning method described in Python: Slicing a list into n nearly-equal-length partitions, but shuffling the result beforehand.
import random
N_FILES = 2
out = [open("test{}.txt".format(i), 'wb') for i in range(min(N_FILES, n))]
fin = open("test.txt", 'rb')
lines = fin.readlines()
random.shuffle(lines)
n = len(lines)
size = n / float(N_FILES)
partitions = [ lines[int(round(size * i)): int(round(size * (i + 1)))] for i in xrange(n) ]
for f, lines in zip(out, partitions):
for line in lines:
f.write(line)
fin.close()
for f in out:
f.close()
The code above will split the input file into N_FILES (defined as a constant at the top) of approximately equal size, but never splitting beyond one line per file. Handling things this way would let you put this into a function that can take a variable number of files to split into without having to alter code for each case.