I believe that the function write_shell_face_loop is writing out the edges in the wrong order --- that is, not the same order that they are read in as, which causes the vertex lists to be permuted, since they are stored in the faces, and the faces have their vertices reconstructed by referencing said edges.