fixed keyvaluepairs in writing files

Exception was thrown before, because for loop over dictionary only
returns key during the loop. Values would have to be extracted manually
from dictionary using get()
Use of .items() makes old construct possible