Used for loop in assertFileWrittenFromList

Refactored by using for loop.