So it works with a loop of smaller amounts? It could be anything really. Is the file opened and closed correctly?