Error when creating a task in separate file in verilog
The problem is probably the nested module declaration. This is not allowed in Verilog, however is possible in SystemVerilog.
Try to declare only the task AddModule() in a separate file without a surounding module declaration. This file can then be included within the scope of another module, e.g. within your testbench (as in your example code).