def write_map(data, key, fname):
    """Write entry-to-parent(s) mapping.

    Parameters
    ----------
    data : dict
        Main data structure.
    key : str
        Metadata key.
    fname : str
        Output file name.

    Returns
    -------
    set of str
        Parent entries.
    """
    pids = set()
    with open(fname, 'w') as f:
        for uid, datum in sorted(data.items()):
            if key in datum:
                print(uid, '\t'.join(datum[key]), sep='\t', file=f)
                pids.update(datum[key])
    return pids