glyphNameToFileName creates a filename for a given glyphname. In order to prevent files being overwritten in caseless file systems, the function adds an underscore if a glyphname starts with an uppercase character. In compound glyphnames used for ligatures, differentiation is required for all partial names, not just the first.
Glyphs in a font with compound names in which the first glyph is the same, but subsequent names only have case differences, like T_H and T_h, these glyphs will overwrite each other as glif.
Second issue here is that the underscore serves a double purpose in compound names. It is the case indicator but also serves as the compound glyph name separator. When adding a _ for each uppercase partial name, it is possible to get names like Th.glif and TH_.glif.