Ignoring other parts, I think you should allocate one more character:
filename = (char*)malloc(strlen(temp)+1); // I added a +1 for last '\0'
// memset(filename,'\0',strlen(temp)); // You dont need this
strcpy(filename, temp);
If you need to remove a file from current directory just the name is enough:
remove("temp.png");
Get rid of those GetCurrentDirectoryA
and related codes.