You probably don't need to throw $order->getData() into a new variable. This will only be to chew on the memory, especially since from this data only one element is required, which can be obtained using a less intensive method.
Instead, try this:
$order = Mage::getModel('sales/order')->load($orderId); $_grand = $order->getGrandTotal(); $custname = $order->getCustomerName(); foreach ($order->getAllItems() as $itemId => $item) {
If $order->getCustomerName() does not work for you, try:
$order->getBillingAddress()->getName();
source share