import tempfile


def save_to_tempfile(data_str):
    """Save a selection to a temporary PDB file and return the file name."""
    # text mode (py3 compatibility)
    tf = tempfile.NamedTemporaryFile("w", suffix=".pdb", dir=".", delete=False)
    tf.write(data_str)
    tf.close()
    return tf.name