To prevent code duplication and to make the implementation simpler, let's add a function that takes care of writing the PE sequnece to an output file. Change-Id: I38733422270f5b9c18187b7f247b84bf21f9121b