When you generate a jar file, it is in a compressed format (like .zip). You cannot simply save a file into the jar. It is technically possible, but is complicated. See here for more info.
The reason it works in netbeans is because when you run a file in netbeans, the code is not yet compressed into a jar. Once you make the jar file, you cannot simply write files into the jar. Try and save your file in a normal directory (not within the jar).