Output file not written properly

I recently started using Nsight eclipse (Cuda 6.5). I created a project with the following source file:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
FILE *fp;

 fp = fopen("test.txt","w");
 fprintf(fp,"This is a test.\n");
 getchar();

fclose(fp);
return 0;

}

When I compile it, Nsight creates a “Debug” folder and puts the executable there. However, when I run it using Nsight Run, an empty “test.txt” file is created in the directory where the source code is located with no line written in it. If I open the command window (Alt+Ctrl+T in Ubuntu 14.04) ad go to the “Debug” directory that Nsight created under the project folder and run the case, everything is ok. That is “test.txt” is created with the line “This is a test” written in it in the “Debug” directory.

I was wondering if somebody could shed light on this issue for me. Is this a bug?

Thanks.