Custom shortcode that writes to file

Your code works for me on a development server. As is, it saves to the site root directory. My guess is that you are trying to write to a directory to which the server does not have write access. I would suggest saving to wp-content/uploads or some other directory where you should reasonably have write access.

$upload_dir = wp_upload_dir();
$myFile = $upload_dir['basedir']."/offer_codes.txt";