Iterate through file object instead of readlines

This should greatly reduce memory consumption: readlines() reads the entire file into memory; iteration prevents memory usage from exploding, while achieving the same effect.