What you are doing is writing the actual echo
shell command to the file, not e.g. 0=0
.
You should only do
fprintf(fp, "%d=%d\n", i, i * i);
PS. You don't need to worry about flushing the file buffers, it will be done automatically when the file is closed, and the file will be closed when the process exits (but it's considered good to explicitly close files that you open, even if it's not technically needed).