As Bob pointed out the problem is reopening your files. Your fileHandles is of type fileHandles :: Map.Map [Char] (IO Handle) It should be fileHandles :: Map.Map [Char] Handle
Something like this should fix it: fileHandles <- Map.fromList `fmap` mapM (\x -> do h <- openFile ("out/" ++ x) WriteMode return (x,h)) allMers Cheers, -- David