In Lua, functions are first-class values.
grades_copy_table = returntable
Here you are assigning grades_copy_table
the function returntable
itself, not its return value. You need to call that function and assign the returned value:
grades_copy_table = returntable()