Looks like you're not closing your files, which can chew up CPU resources, so it's good practice to do that, or even better, use context management:
```
with codecs.open(filename) as outfile:
    #do whatever with outfile
```