After updating the Layer value [DXF 8] in the 'entities' DXF List, you are using the original list containing the old Layer value when updating the Text Generation Flag (in Text) or the Attachment Point (in MText) - Note that DXF 71 means different things for Text & MText!
Hence, since the original DXF Data is used, the Layer value is updated back to its original value.