I think the steps you were trying would normally work, but it looks like your text file was likely quarantined (browsers and mail clients usually quarantine "unsafe" files by default, and text files are considered unsafe because they could be shell scripts).
The quarantine marker is stored as an "extended attribute", which is a kind of metadata attached to the file in the filesystem's data structures. The exact ID of the quarantine attribute is "com.apple.quarantine". The
xattr(1) command can be used to create, view, edit, and delete extended attributes.
So, first remove the quarantine (extended attribute) from the text file you're trying to open:
xattr -d com.apple.quarantine codes.txt
…then follow the steps you were already trying.