I'm not seeing something that would cause this. The 'error writing' message is ambiguous. "error opening" would mean either the foldername or filename doesn't yet exist, but "error writing" means the filename does exist. There are a couple of causes I can think of, but they shouldn't be happening in this context.

The file could have the 'read only' attribute set, but this is unlikely unless it was specifically set due to being copied off a CD/DVD media where it was set, or if you specifically set it. You can verify this isn't the case by doing:

/run cmd /k attrib scripts\data\AutoJoin.mrk

Typically there would only be the A attribute to the left of the filename, and there should not be the "R" for read-only.

If there is the R attribute, you can remove it like
/run cmd /c attrib -r scripts\data\AutoJoin.mrk

The error could be caused by not having write permissions to the file, but this shouldn't happen unless you're doing something like writing to a subfolder beneath c:\program files\ or c:\windows\
It's still possible for a file to have blocked write permissions if you used a utility to 'move' the filename from another folder where you didn't have write permissions. If that's the case, you'd want to *move* it back there, then *copy* it here.

==

A couple other suggestions for your script:

+ Use relative pathnames, so you don't need to put quotes around everything to protect against $mircdir having a space in it. By default, if the pathfilename doesn't begin with \ or driveletter:\ then it carries an implied $mircdir in front of it, so you could change _doc to

alias _doc { return $+(scripts\data\,$1,.mrk) }

Also, you want to get in the habit of using switches with $read.

If you don't want to have it evaluate %variable or $identifier contained in the returned text, nor for it to waste time looking for it, then use the r switch.

If you don't want to have it waste time checking if line#1 is numeric, and if that's so, to have it treat that as if it's the number of lines in the file, then use the t switch.

Since you're using a .ini format the 't' issue isn't probably going to affect you, and you're probably not reading/writing strings containing words that being with $ or %, but it's good practice to be in the habit of using switches rt unless you DO want that behavior, and have taken steps to ensure that any text has been sanitized before being written to that file.